<template>
  <div class="container">
    <div class="content">
      <div class="avatar">
        <img :src="rule.avatar" alt />
      </div>
      <p>{{rule.nickname}}</p>
      <h3>
        <div class="item" :style="{'background-position':-30/37.5+'rem 0'}" v-if="rule.score/10==1"></div>
        <div
          class="item"
          :style="{'background-position':-120/37.5+'rem 0'}"
          v-if="rule.score/10==3"
        ></div>
        <div
          class="item"
          :style="{'background-position':-32/37.5+'rem 0'}"
          v-if="rule.score/10==10"
        ></div>
        <div
          class="item"
          :style="{'background-position':-360/37.5+'rem 0'}"
          v-if="rule.score/10==9"
        ></div>
        <div
          class="item"
          :style="{'background-position':-320/37.5+'rem 0'}"
          v-if="rule.score/10==8"
        ></div>
        <div
          class="item"
          :style="{'background-position':-280/37.5+'rem 0'}"
          v-if="rule.score/10==7"
        ></div>
        <div
          class="item"
          :style="{'background-position':-240/37.5+'rem 0'}"
          v-if="rule.score/10==6"
        ></div>
        <div
          class="item"
          :style="{'background-position':-200/37.5+'rem 0'}"
          v-if="rule.score/10==5"
        ></div>
        <div
          class="item"
          :style="{'background-position':-160/37.5+'rem 0'}"
          v-if="rule.score/10==4"
        ></div>
        <div class="item" :style="{'background-position':-70/37.5+'rem 0'}" v-if="rule.score/10==2"></div>
        <div class="item0" v-if="rule.score/10<=10"></div>
        <div class="item0" v-if="rule.score/10==10"></div>
        <small>分</small>
      </h3>
      <h4 class="first-child" v-if="rule.exchange_code==''&&rule.is_order!=1">您未进入到排行榜</h4>
      <h4 v-if="rule.score==100" class="first-child">
        您的答题排名第
        <div class="order">{{rule.order}}</div>位
      </h4>
      <h4 v-if="rule.exchange_code!=''">
        领奖编码：
        <span class="number" :class="{'active':rule.is_finish!=0}">{{rule.exchange_code}}</span>
        <span class="status" v-if="rule.is_finish==0" style="color:#07E288">未领奖</span>
        <span class="status" v-if="rule.is_finish==1" style="color:#B1B1B1">已领奖</span>
      </h4>
      <div class="des" v-if="rule.exchange_code!=''">注：凭本界面领取，截图无效</div>
      <h4 v-else class="first-child">{{rule.order}}</h4>
      <h4>提交时间：{{rule.add_time}}</h4>
      <h4>{{rule.msg}}</h4>
      <div class="btns" @click="goTop">
        <span class="iconfont"></span> 查看Top 30
      </div>
    </div>
    <div class="btn-group">
      <div class="back" @click="goBack">返回</div>
      <div class="answers" @click="goQuestion">查看答题详情</div>
    </div>
  </div>
</template>

<script>
export default {
  data() {
    return {
      rule: "",
      text_tip: "",
      id: ""
    };
  },
  mounted() {
    this.id = this.$route.query.id;
    if (localStorage.end) {
      this.rule = JSON.parse(localStorage.end);
    } else {
      this.$router.replace({ path: "/yue" });
    }
  },
  methods: {
    goBack() {
      localStorage.removeItem("end");
      this.$router.replace({ path: "/questionList" });
    },
    getRules() {
      this.$api.getRules().then(res => {
        this.rule = res.data;
        this.text_tip = res.data.text_tip.replace(/↵/g, "\n");
      });
    },
    goTop() {
      this.$router.push({ path: "/top", query: { id: this.id } });
    },
    goQuestion() {
      this.$router.push({
        path: "/questionDetail",
        query: {
          id: this.id,
          topic_rid: this.rule.topic_rid
        }
      });
    }
  }
};
</script>

<style lang="scss" scoped>
.container {
  // width: 100%;
  min-height: 100vh;
  background: url(../.././img/yue/22.png) no-repeat #c0292c;
  background-size: cover;
  padding: 80px 0px 0;
  .content {
    background: url(../.././img/yue/4.png) no-repeat;
    background-size: cover;
    width: 320px;
    height: 450px;
    margin: 0 auto;
    position: relative;
    padding: 0 25px;
    z-index: 1;
    .avatar {
      width: 94px;
      height: 94px;
      border-radius: 50%;
      border: 3px solid rgba(250, 220, 150, 1);
      box-shadow: 0px 3px 4px 1px rgba(173, 173, 173, 0.47);
      position: absolute;
      top: -47px;
      left: 50%;
      transform: translateX(-50%);
      z-index: 3;
      overflow: hidden;
      img {
        display: block;
        width: 100%;
      }
    }
    p {
      padding-top: 60px;
      text-align: center;
      color: #000000;
      font-size: 17px;
      font-weight: bold;
      background: transparent;
    }
    .iconfont {
      display: inline-block;
      width: 28px;
      height: 28px;
      background: url(../.././img/yue/top.png) no-repeat;
      background-size: contain;
      vertical-align: middle;
    }
    h4 {
      margin-top: 5px;
      font-size: 15px;
      line-height: 24px;
      &.first-child {
        margin-top: 20px;
        font-size: 17px;
        .item {
          background: url(../.././img/yue/0.png) no-repeat;
          background-size: cover;
          background-position: 90px 0;
          height: 38px;
          width: 40px;
          display: inline-block;
        }
        .order {
          font-size: 35px;
          font-weight: bold;
          color: #9d0e0d;
          display: inline-block;
          margin: 0 15px;
        }
      }
      .number {
        font-size: 23px;
        color: #c02929;
        &.active {
          color: #b0b0b0;
          text-decoration: line-through;
        }
      }
    }
    .btns {
      width: 220px;
      height: 50px;
      line-height: 50px;
      text-align: center;
      color: #c02929;
      background: rgba(249, 227, 203, 1);
      box-shadow: 0px 4px 7px 0px rgba(162, 162, 162, 0.3);
      border-radius: 24px;
      font-size: 18px;
      font-weight: bold;
      margin: 15px auto 0;
    }
  }
  h3 {
    font-size: 30px;
    font-weight: bold;
    color: #000000;
    text-align: center;
    margin-top: 24px;
    .item0 {
      background: url(../.././img/yue/0.png) no-repeat;
      background-size: cover;
      background-position: 10px 0;
      height: 38px;
      width: 40px;
      display: inline-block;
      margin-left: -15px;
    }
    .item {
      background: url(../.././img/yue/0.png) no-repeat;
      background-size: cover;
      background-position: 90px 0;
      height: 38px;
      width: 40px;
      display: inline-block;
    }
    small {
      font-size: 17px;
    }
  }
  .des {
    display: block;
    line-height: 18px;
    white-space: pre-wrap;
    font-size: 12px;
    color: #ff0000;
    font-weight: bold;
  }
  .btn-group {
    width: 80%;
    margin: 40px auto 0;
    .back {
      width: 102px;
      height: 48px;
      line-height: 48px;
      text-align: center;
      color: #9d100f;
      background: rgba(255, 255, 255, 1);
      box-shadow: 0px 4px 12px 1px rgba(162, 162, 162, 0.3);
      border-radius: 24px;
      font-weight: bold;
      font-size: 18px;
      display: inline-block;
      margin: 0 15px;
    }
    .answers {
      width: 158px;
      height: 48px;
      line-height: 48px;
      background: rgba(255, 255, 255, 1);
      box-shadow: 0px 4px 12px 1px rgba(162, 162, 162, 0.3);
      border-radius: 24px;
      color: #9d100f;
      text-align: center;
      font-weight: bold;
      font-size: 18px;
      display: inline-block;
    }
  }
}
</style>